unit selVistas;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, jpeg, Mask, Menus;

type
  TfrmDisVistas = class(TForm)
    Panel1: TPanel;
    imgSelPresup: TImage;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    lblPresupuesto: TLabel;
    lblDenominacion: TLabel;
    chkInterno: TCheckBox;
    chkHistorico: TCheckBox;
    Panel3: TPanel;
    Panel8: TPanel;
    Panel2: TPanel;
    Panel57: TPanel;
    Image9: TImage;
    Label9: TLabel;
    Panel58: TPanel;
    chkMembrete: TCheckBox;
    lblCompleto: TLabel;
    lblManoObra: TLabel;
    lblMateriales: TLabel;
    lblGlobales: TLabel;
    Image6: TImage;
    chkIva: TCheckBox;
    chkObs: TCheckBox;
    Label27: TLabel;
    edtIva: TEdit;
    chkPrecios: TCheckBox;
    chkDiscriminado: TCheckBox;
    Image1: TImage;
    Image3: TImage;
    Image4: TImage;
    Shape1: TShape;
    Shape2: TShape;
    chkIPC: TCheckBox;
    Shape3: TShape;
    Label1: TLabel;
    edtIVAIPC: TEdit;
    procedure imgSelPresupClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Label9Click(Sender: TObject);
    procedure chkInternoClick(Sender: TObject);
    procedure edtIvaKeyPress(Sender: TObject; var Key: Char);
    procedure lblCompletoClick(Sender: TObject);
    procedure lblMaterialesClick(Sender: TObject);
    procedure lblGlobalesClick(Sender: TObject);
    procedure lblManoObraClick(Sender: TObject);
    procedure chkPreciosClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure chkIPCClick(Sender: TObject);
  private
    FidUsuario: word;
    FidPre: integer;
    procedure ActualizarEtiquetas;
    procedure SetidUsuario(const Value: word);
    procedure seteoIPC;
    procedure SetidPre(const Value: integer);
  published
    property idUsuario: word read FidUsuario write SetidUsuario;
    property idPre: integer read FidPre write SetidPre;
  public
    constructor Entrar (Aowner: TComponent; idUs: word);
  end;

var
  frmDisVistas: TfrmDisVistas;
  id : integer;
implementation

uses selpresup, MDatos, verPresup, Recursos, VerMoDet,
  VerMatDet, verGlobal;

{$R *.dfm}

constructor TfrmDisVistas.Entrar (Aowner: TComponent; idUs: word);
begin
  if (frmSelPresup.Entrar(3, idUs) = mrOk) and (frmSelPresup.idPresup <> 0) then
  begin
    inherited Create(Aowner);
    id := frmSelPresup.idPresup;
    self.idUsuario := idUs;
    ActualizarEtiquetas;
    chkInterno.Checked := True;
    chkHistorico.Checked := True;
    ShowModal;
  end;
end;

procedure TfrmDisVistas.imgSelPresupClick(Sender: TObject);
begin
  if (frmSelPresup.Entrar(0, self.idUsuario) = mrOk) then
  begin
    id := frmSelPresup.idPresup;
    ActualizarEtiquetas;
  end;
end;

procedure TfrmDisVistas.ActualizarEtiquetas;
var
  sql : string;
begin
  try
    sql := 'SELECT id_presupuesto, denominacion, iva FROM presupuesto WHERE id_presupuesto = '
    +IntToStr(id);
    EjecutarSql(Datos.qryVar, sql);
    lblPresupuesto.Caption := Datos.qryVar.Fields [0].AsString;
    lblDenominacion.Caption := Datos.qryVar.Fields [1].AsString;
    edtIva.Text := FloatToStrF(Datos.qryVar.Fields [2].AsFloat, ffNumber, 15, 2);
  finally
    Datos.qryVar.Close;
  end;
end;

procedure TfrmDisVistas.FormCreate(Sender: TObject);
begin
  Acomodo(frmDisVistas);
end;

procedure TfrmDisVistas.Label9Click(Sender: TObject);
begin
  Close;
end;

procedure TfrmDisVistas.chkInternoClick(Sender: TObject);
begin
  chkIva.Enabled := not chkInterno.Checked;
  chkIva.Checked := True;
end;

procedure TfrmDisVistas.edtIvaKeyPress(Sender: TObject; var Key: Char);
begin
  if not((StrScan('0123456789.-',Key) <> nil) or (Key=Char(VK_BACK))) then
    Key := #0;   
end;

procedure TfrmDisVistas.lblCompletoClick(Sender: TObject);
var
  IVAIPC: Double;
begin
  if self.chkIPC.Checked then
  begin
    try
      IVAIPC := StrToFloat(self.edtIVAIPC.Text);
    except
      IVAIPC := 0.00;
    end;
  end
  else
    IVAIPC := 0.00;
  TfrmMatMoDet.Entrar(self, id, chkInterno.Checked, chkHistorico.Checked, chkMembrete.Checked,
  chkPrecios.Checked, chkDiscriminado.Checked, chkIva.Checked, chkObs.Checked, self.chkIPC.Checked, IVAIPC);
end;

procedure TfrmDisVistas.lblMaterialesClick(Sender: TObject);
var
  fltIva: Double;
begin
  try
    fltIva := StrToFloat(edtIva.Text);
  except
    fltIva := 0;
  end;
  TfrmMatDet.Entrar(self, id, chkInterno.Checked, chkHistorico.Checked,
  chkMembrete.Checked, chkPrecios.Checked, chkIva.Checked, fltIva);
end;

procedure TfrmDisVistas.lblGlobalesClick(Sender: TObject);
begin
  TfrmVerGlobal.Entrar(self, id, chkInterno.Checked, chkHistorico.Checked, chkMembrete.Checked,
  chkPrecios.Checked, chkIva.Checked);
end;

procedure TfrmDisVistas.lblManoObraClick(Sender: TObject);
begin
  TfrmMoDet.Entrar(self, id, chkInterno.Checked, chkHistorico.Checked,
  chkMembrete.Checked, chkPrecios.Checked, chkIva.Checked, self.chkObs.Checked);
end;

procedure TfrmDisVistas.chkPreciosClick(Sender: TObject);
begin
  chkDiscriminado.Checked := chkPrecios.Checked;
  chkDiscriminado.Enabled := chkDiscriminado.Checked;
end;

procedure TfrmDisVistas.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmDisVistas.SetidUsuario(const Value: word);
begin
  FidUsuario := Value;
end;

procedure TfrmDisVistas.chkIPCClick(Sender: TObject);
begin
  self.seteoIPC;
end;

procedure TfrmDisVistas.seteoIPC;
begin
  self.edtIVAIPC.Enabled := self.chkIPC.Checked;
  if self.edtIVAIPC.Enabled then
  begin
    self.chkInterno.Checked := False;
    self.chkInterno.Enabled := False;
    self.chkIva.Checked := True;
    self.chkIva.Enabled := False;
    self.Image1.Enabled := False;
    self.Image3.Enabled := False;
    self.Image4.Enabled := False;
    self.lblManoObra.Enabled := False;
    self.lblMateriales.Enabled := False;
    self.lblGlobales.Enabled := False;
    self.Label27.Enabled := False;
    self.edtIva.Enabled := False;
  end
  else
  begin
    self.chkInterno.Enabled := True;
    self.chkIva.Enabled := True;
    self.Image1.Enabled := True;
    self.Image3.Enabled := True;
    self.Image4.Enabled := True;
    self.lblManoObra.Enabled := True;
    self.lblMateriales.Enabled := True;
    self.lblGlobales.Enabled := True;
    self.Label27.Enabled := True;
    self.edtIva.Enabled := True;
  end;
end;

procedure TfrmDisVistas.SetidPre(const Value: integer);
begin
  FidPre := Value;
end;

end.

